//
//  TZYDebrisTableDetailViewController.m
//  Moment
//
//  Created by dllo on 15/12/29.
//  Copyright © 2015年 片刻. All rights reserved.
//

#import "TZYDebrisTableDetailViewController.h"

@interface TZYDebrisTableDetailViewController ()<UIWebViewDelegate>

@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, copy) NSString *html;

@end


@implementation TZYDebrisTableDetailViewController


- (void)dealloc
{
    self.webView.scrollView.delegate = nil;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor redColor];
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"viewB.jpg"]]];
    
    UIImage *image = [UIImage imageNamed:@"fanghuipic.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self action:@selector(leftButtonAction:)];
    
    
    //创建WebView
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -60, SCREEN_WIDTH, SCREEN_HEIGHT + 80)];
    self.webView.delegate  = self;
    [self.view addSubview:self.webView];
    
    //    self.webView.userInteractionEnabled = ;
    [(UIScrollView *)[[self.webView subviews] objectAtIndex:0] setBounces:NO];
    //self.webView.scrollView.scrollEnabled  = NO;
    
    
    //调用WebView请求方法
    [self getWebViewData];
    


    
}

- (void)getWebViewData
{
    
    NSLog(@"%@", self.contentID);
    //http://api2.pianke.me/timeline/info?contentid=568280125e7743da3f8b489b&client=2
    NSString *urlStr = @"http://api2.pianke.me/timeline/info";
    NSString *para = [NSString stringWithFormat:@"contentid=%@&client=2", self.contentID];
    
    
    [GetData postUrl:urlStr body:para result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        NSDictionary *dic = [(NSDictionary *)result objectForKey:@"data"];
        
        self.html = [dic objectForKey:@"html"];
        
        NSURL *url = [NSURL URLWithString:urlStr];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [self.webView loadRequest:request];
        
        
    } failure:^(NSError *error) {
        
        
    }];

    
    
}




- (void)leftButtonAction:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
